package com.leetcode.LC;

public class LC704 {
    public int search(int[] nums, int target) {

        int a = 0, b = nums.length - 1;
        int mid = (a + b) / 2;//mid=a+(b-a)/2;
        while (a <= b) {
            if (nums[mid] == target) {
                return mid;
            }
            if (target > nums[mid]) {
                a = mid + 1;
            }
            if (target < nums[mid]) {
                b = mid - 1;
            }
            mid = (a + b) / 2;
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new LC704().search(new int[]{-1, 0, 1}, 1));
    }
}
